package com.yupi.springbootinit.mq.TtlMq;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class SingleProducer {
    public static final String QUEUE_NAME= "ttl_queue";
    public static void main(String[] args) {
        //1：创建一个连接工厂对象，对象可以连接Rabbit服务
        ConnectionFactory factory = new ConnectionFactory();
        //2：指定连接服务的主机名以及账号密码
        factory.setHost("192.168.1.183");
        factory.setUsername("lfc");
        factory.setPassword("123456");
        //3：利用工厂创建一个连接Rabbit服务
        try {
            Connection connection = factory.newConnection();
            //4：通过连接常见一个新的频道
            Channel channel = connection.createChannel();
            String message = "这是一条消息";
            //6：通过channel操作消息对比如发送消息
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
            System.out.println("sent:"+message);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            throw new RuntimeException(e);
        }

    }
}
